package at.jsug.topicvoting.gwt1.client.remote.rest;

import at.jsug.topicvoting.gwt1.client.vo.Topic;

import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;

public class TopicsConverter {

	
	public static Topic json2object(JSONObject topicObj) {
		
		
		JSONString val = (JSONString) topicObj.get("id");
		final long id = Long.parseLong(val.stringValue());
		
		final String title = ((JSONString) topicObj.get("title")).stringValue();
		
		// TODO
		final int votes = 0;
		final boolean yetVoted = false;
		
		return Topic.newNeedTopic(id, title, votes, yetVoted);
	}
	
	public static String object2json(Topic topic) {
		return "{ \"id\" : \"" + topic.getId() + "\", \"title\": \"" + topic.getTitle() + "\" }";
	}
	
}
